
const { NodeSSH } = require("node-ssh")
const path = require('path');
// 本地目录路径和远程目录路径
const localSrc = __dirname + "\\README.zip";
const remoteSrc = '/www/wwwroot/42.193.231.115/' + path.basename(localSrc);
const ssh = new NodeSSH()
ssh.connect({
    host: '42.193.231.115',
    port: 22,
    username: 'root',
    password: 'Jcy123321789',
    // privateKey: readFileSync('/path/to/my/key')
}).then(() => {
    ssh.putFile(localSrc, remoteSrc).then(() => {
        console.log("文件上传成功");
    }).catch(err => {
        console.log("文上传失败：", err);
    }).finally(() => ssh.dispose())

    ssh.execCommand("cd /www/wwwroot/42.193.231.115; unzip README.zip").then(res => {
        console.log("成功", res);
    }).catch(e => {
        console.log(e);
    })

}).catch(err => {
    console.log("ssh连接失败：", err);
})
